package com.atguigu.flink.chapter05.transform;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.stream.Stream;

/*
        基本转换算子  ---->  map
 */
public class MapDemo {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port",2000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);

        env.fromElements(10,20,30,50)
                //.map(value -> value * value)
                .map(new MapFunction<Integer, Tuple2<Long,Integer>>() {
                    @Override
                    public Tuple2<Long, Integer> map(Integer value) throws Exception {
                        return Tuple2.of(1L,value);
                    }
                })
                .print();

        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


//public class MapDemo {
//    public static void main(String[] args) {
//        Configuration conf = new Configuration();
//        conf.setInteger("rest.port",2000);
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
//        env.setParallelism(1);
//
//        env.fromElements(20,23,45,67,89)
//                //.map(value -> value)
//                .map(new MapFunction<Integer, Tuple2<Long,Integer>>() {
//                    @Override
//                    public Tuple2<Long, Integer> map(Integer value) throws Exception {
//                        return Tuple2.of(1L,value);
//                    }
//                })
//                .print();
//        try {
//            env.execute();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//    }
//}